import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';

import '../../../entity/meeting_data.dart';
import '../../../generated/assets.dart';
import '../../../generated/l10n.dart';
import '../../../routes/router.dart';
import '../../../utils/utils.dart';
import 'metting_all_logic.dart';

class Metting_allPage extends GetView<Metting_allLogic> {
  const Metting_allPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        centerTitle: true,
        title: Text(
          S.current.allMeeting,
          style: TextStyle(fontSize: 16.sp, fontWeight: FontWeight.w600),
        ),
      ),
      body: Container(
        color: const Color(0xffF8F8F8),
        child: Obx(() {
          return ListView(
            children: [
              sectionWithTitle(S.current.myMeeting, controller.myMeetingList),
              sectionWithTitle(S.current.hadEnd, controller.endMeetingList),
            ],
          );
        }),
      ),
    );
  }

  Widget sectionWithTitle(String title,List<MeetingData> list){
    return list.isNotEmpty ? Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(title,style: TextStyle(fontSize: 16.sp,fontWeight: FontWeight.w600,color: const Color(0xFF333333)),).paddingOnly(top: 20.h,bottom: 10.h,left: 15.w),
        ListView.separated(
            physics: const NeverScrollableScrollPhysics(),
            shrinkWrap: true,
            separatorBuilder: (context, index) {
              return SizedBox(
                height: 15.h,
              );
            },
            itemCount: list.length,
            itemBuilder: (context, index) {
              MeetingData data = list[index];
              return meetingListWidget(data);
            })
      ],
    ) : Container();
  }

  Widget meetingListWidget(MeetingData data) {
    String state = Utils.meetingState(data);
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        GestureDetector(
          onTap: () {
            Get.toNamed(AppRoutes.mettingDetail,arguments: data);
          },
          child: Container(
            margin: EdgeInsets.only(left: 15.w, right: 15.w),
            padding: EdgeInsets.symmetric(vertical: 15.h, horizontal: 15.w),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(8.r),
              color: Colors.white,
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: [
                        Container(
                          decoration: BoxDecoration(
                              color: Utils.stateColor(state), shape: BoxShape.circle),
                          width: 6.w,
                          height: 6.w,
                        ),
                        SizedBox(
                          width: 6.w,
                        ),
                        Text(
                          data.meetingName ?? '',
                          style: TextStyle(
                              color: const Color(0xff333333),
                              fontSize: 14.sp,
                              fontWeight: FontWeight.w600),
                        ),
                      ],
                    ),
                    Text(
                      state,
                      style: TextStyle(
                          color: Utils.stateColor(state), fontSize: 12.sp),
                    ),
                  ],
                ),
                const Divider(color: Color.fromRGBO(0, 0, 0, 0.06))
                    .marginSymmetric(vertical: 15.h),
                Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(
                          Utils.getMeetingTime(data.meetingBeginTime),
                          style: TextStyle(
                              color: const Color(0xff333333),
                              fontSize: 16.sp,
                              fontWeight: FontWeight.w700),
                        ),
                        Text(
                          Utils.getMeetingDate(data.meetingBeginTime),
                          style: TextStyle(
                              color: const Color.fromRGBO(51, 51, 51, 0.6),
                              fontSize: 12.sp,
                              fontWeight: FontWeight.w500),
                        )
                      ],
                    ),
                    Expanded(
                      child: Row(
                        children: [
                          Expanded(
                            child: Divider(
                              color: const Color.fromRGBO(0, 0, 0, 0.06),
                              endIndent: 5.w,
                              indent: 10.w,
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.symmetric(horizontal: 10.w),
                            alignment: Alignment.center,
                            height: 18.h,
                            decoration: BoxDecoration(
                                color: const Color.fromRGBO(51, 51, 51, 0.1),
                                borderRadius: BorderRadius.circular(4.r)),
                            child: Text(
                              '${Utils.timeDifference(data.meetingBeginTime!, data.meetingEndTime!)}小时',
                              style: TextStyle(
                                  color: const Color(0xff333333),
                                  fontSize: 10.sp,
                                  fontWeight: FontWeight.w500),
                            ),
                          ),
                          Expanded(
                            child: Divider(
                              color: const Color.fromRGBO(0, 0, 0, 0.06),
                              endIndent: 10.w,
                              indent: 5.w,
                            ),
                          ),
                        ],
                      ),
                    ),
                    Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(
                          Utils.getMeetingTime(data.meetingEndTime),
                          style: TextStyle(
                              color: const Color(0xff333333),
                              fontSize: 16.sp,
                              fontWeight: FontWeight.w700),
                        ),
                        Text(
                          Utils.getMeetingDate(data.meetingEndTime),
                          style: TextStyle(
                              color: const Color.fromRGBO(51, 51, 51, 0.6),
                              fontSize: 12.sp,
                              fontWeight: FontWeight.w500),
                        )
                      ],
                    ),
                  ],
                ).paddingSymmetric(horizontal: 15.w),
                Row(
                  children: [
                    SvgPicture.asset(
                      Assets.svgLoc,
                      width: 18,
                      height: 18,
                      color: const Color(0xff535353),
                    ),
                    Padding(
                      padding: EdgeInsets.only(left: 10.w),
                      child: Text(
                        data.meetingAddress ?? '',
                        style: TextStyle(
                            color: const Color(0xff999999),
                            fontSize: 13.sp,
                            fontWeight: FontWeight.w500),
                      ),
                    ),
                  ],
                ).marginOnly(top: 20.h),
                Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    SvgPicture.asset(
                      Assets.svgMember,
                      width: 18,
                      height: 18,
                      color: const Color(0xff535353),
                    ),
                    Expanded(
                      child: Text(
                        data.participants ?? '',
                        style: TextStyle(
                            color: const Color(0xff999999),
                            fontSize: 13.sp,
                            fontWeight: FontWeight.w500),
                      ).paddingOnly(left: 10.w),
                    ),
                  ],
                ).marginOnly(top: 10.h),
              ],
            ),
          ),
        )
      ],
    );
  }
}
